package com.changgou.business.listener;


import okhttp3.*;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;

@Component   //声明这个是一个Bean
public class AdListener {


    @RabbitListener(queues = "ad_update_queue")  //监听的队列 ad_update_queue
    public void receiveMessag(String message){

        System.out.println("接受到的消息为:"+ message);


        //发起远程调用
        OkHttpClient okHttpClient =new OkHttpClient();

        //创建请求路径 对象
        String url = "http://192.168.200.128/ad_update?position"+message;

        //创建request对象
        Request request = new Request.Builder().url(url).build();

        //得到了一个call对象
        Call call = okHttpClient.newCall(request); // 需要一个request对象

        //通过call对象发起请求
        call.enqueue(new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
                //请求失败
                e.printStackTrace();

            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                //请求成功
                System.out.println("请求成功："+response.message());
            }
        });

    }
}
